package view;
import java.awt.EventQueue;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;

import java.awt.Color;


public class MainRFP {

	private JFrame frame;
	private JTextField pinField;
	private JPasswordField passwordField;
	private JLabel label;
	private JPanel analystDisplay;
	private JPanel adminDisplay;
	private JPanel propose;
	private JPanel search;
	private JPanel panel_2;
	private JTextField proposalText;
	private JTextField textField_2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainRFP window = new MainRFP();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainRFP() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new CardLayout(0, 0));
		
		/* Login */
		JPanel loginDisplay = new JPanel();
		frame.getContentPane().add(loginDisplay, "name_1416201222433014000");
		loginDisplay.setLayout(null);
		
		pinField = new JTextField("PIN");
		pinField.setBounds(140, 154, 155, 28);
		loginDisplay.add(pinField);
		pinField.setColumns(10);
		
		passwordField = new JPasswordField("password");
		passwordField.setBounds(140, 186, 155, 20);
		loginDisplay.add(passwordField);
		
		JButton loginButton = new JButton("Login");
		loginButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent theEvent) {
				final String pinNumber = pinField.getText();
				final String password = passwordField.getText();
				//Verify to database.
				
				if (pinNumber.equals("1111") && password.equals("hi")) {
					System.out.println("logged in");
				}
			}
		});
		loginButton.setBounds(161, 218, 117, 29);
		loginDisplay.add(loginButton);
		/*
		try {
			label = new JLabel(new ImageIcon((BufferedImage) ImageIO.read(getClass().getResource("dabear.jpg"))));
		} catch (final IOException e) {
			System.out.println(e);
		}
		label.setBounds(182, 38, 75, 111);
		loginDisplay.add(label);
		*/
		
		/* Analyst */
		analystDisplay = new JPanel();
		frame.getContentPane().add(analystDisplay, "name_1416201826406679000");
		analystDisplay.setLayout(new CardLayout(0, 0));
		
		addPanel();
		
		search = new JPanel();
		analystDisplay.add(search, "name_1416202120523766000");
		search.setLayout(null);
		
		JPanel panel_3 = new JPanel();
		panel_3.setBackground(Color.WHITE);
		panel_3.setBounds(60, 21, 362, 137);
		search.add(panel_3);
		panel_3.setLayout(null);
		
		JTextArea textArea = new JTextArea();
		textArea.setBounds(360, 6, -357, 125);
		panel_3.add(textArea);
		
		textField_2 = new JTextField();
		textField_2.setBounds(60, 169, 362, 28);
		search.add(textField_2);
		textField_2.setColumns(10);
		
		JButton btnNewButton_2 = new JButton("New button");
		btnNewButton_2.setBounds(235, 223, 117, 29);
		search.add(btnNewButton_2);
		
		JRadioButton rdbtnNewRadioButton_3 = new JRadioButton("New radio button");
		rdbtnNewRadioButton_3.setBounds(60, 197, 141, 23);
		search.add(rdbtnNewRadioButton_3);
		
		JRadioButton rdbtnNewRadioButton_4 = new JRadioButton("New radio button");
		rdbtnNewRadioButton_4.setBounds(60, 224, 141, 23);
		search.add(rdbtnNewRadioButton_4);
		
		JRadioButton rdbtnNewRadioButton_5 = new JRadioButton("New radio button");
		rdbtnNewRadioButton_5.setBounds(60, 249, 141, 23);
		search.add(rdbtnNewRadioButton_5);
		
		panel_2 = new JPanel();
		analystDisplay.add(panel_2, "name_1416202123858036000");
		
		/* Admin */
		adminDisplay = new JPanel();
		frame.getContentPane().add(adminDisplay, "name_1416201945231564000");
		
	}
	
	void addPanel() {
		propose = new JPanel();
		analystDisplay.add(propose, "name_1416202117007720000");
		propose.setLayout(null);
		
		proposalText = new JTextField();
		proposalText.setBounds(26, 16, 399, 148);
		propose.add(proposalText);
		proposalText.setColumns(10);
		
		JRadioButton porposedQuestion = new JRadioButton("Propose Question");
		porposedQuestion.setBounds(36, 176, 151, 23);
		propose.add(porposedQuestion);
		
		JRadioButton proposedAnswer = new JRadioButton("Propose Answer");
		proposedAnswer.setBounds(36, 200, 141, 23);
		propose.add(proposedAnswer);
		
		JRadioButton proposedKeyword = new JRadioButton("Propose Keyword");
		proposedKeyword.setBounds(36, 224, 141, 23);
		propose.add(proposedKeyword);
		
		JButton proposeButton = new JButton("Submit");
		proposeButton.setBounds(238, 199, 117, 29);
		propose.add(proposeButton);
	}
}